Skip to content

Conversation

Enigmatisms
Copy link
Contributor

PR Category

Operator Mechanism

PR Types

New features

Description

#74446 re-open 的 PR。

增加了 paddle.compat.split。此 API 的函数签名、行为与torch.split完全一致。具体见 torch.split 文档以及后续更新的 paddle doc。增加了如下机制:

  • split_size_or_sections 在各种情况下(动、静态图)正确计算 num_or_sections 的方法。此API不再要求分成相同大小的 tensor(最后一个tensor可以略小,取决于 int 类型的 split size 是否能整除 shape 对应维度)。
  • 增加了 ForbidKeywordsDecorator 装饰器:此装饰器接收一个或者多个禁止用户输入(可能混淆)的 keyword arguments,并接收一个“建议调用函数的名称”。当用户输入错误的 keyword arguments 时,将会报错提示。例子:
# paddle.split 误用为 paddle.compat.split
paddle.split(some_tensor, split_size_or_sections = 3, dim = 0)

报错如下:

TypeError: paddle.split() received unexpected keyword arguments 'tensor', 'split_size_or_sections', 'dim'. 
Did you mean to use paddle.compat.split() instead?

对于 paddle.compat.split 误用为 paddle.split同样有此操作。

  • 新增了 test_compat_split.py 用于测试输入输出 shape,size 以及是否能正确报错
  • 新增了 test_compat_split_static.py 用于测试静态图正确性

Pcard-89620

Copy link

paddle-bot bot commented Aug 9, 2025

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@codecov-commenter
Copy link

codecov-commenter commented Aug 9, 2025

Codecov Report

❌ Patch coverage is 91.39785% with 8 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@ab55c08). Learn more about missing BASE report.

Files with missing lines Patch % Lines
python/paddle/tensor/compat.py 89.33% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop   #74506   +/-   ##
==========================================
  Coverage           ?   91.39%           
==========================================
  Files              ?        4           
  Lines              ?       93           
  Branches           ?        0           
==========================================
  Hits               ?       85           
  Misses             ?        8           
  Partials           ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Enigmatisms
Copy link
Contributor Author

/re-run all-failed

@Enigmatisms
Copy link
Contributor Author

/re-run all-failed

@Enigmatisms
Copy link
Contributor Author

/re-run all-failed

1 similar comment
@Enigmatisms
Copy link
Contributor Author

/re-run all-failed

zhangbo9674
zhangbo9674 previously approved these changes Aug 15, 2025
Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Enigmatisms
Copy link
Contributor Author

/re-run all-failed

1 similar comment
@Enigmatisms
Copy link
Contributor Author

/re-run all-failed

@Enigmatisms
Copy link
Contributor Author

/re-run all-failed

1 similar comment
@Enigmatisms
Copy link
Contributor Author

/re-run all-failed

@Enigmatisms
Copy link
Contributor Author

/re-run all-failed

@zhangbo9674 zhangbo9674 merged commit 7f0baf6 into PaddlePaddle:develop Aug 15, 2025
98 of 105 checks passed
@Enigmatisms Enigmatisms deleted the split_api branch August 29, 2025 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants